﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DNNspot.LiveChat.DataModel
{
    public partial class Client
    {
        public static Client Create(int portalId, int userId, string firstName, string lastName, string email, string ip)
        {
            var client = new Client();
            client.PortalId = portalId;
            client.UserId = userId > -1 ? userId : (int?)null;
            client.FirstName = firstName;
            client.LastName = lastName;
            client.Email = email;
            client.Ip = ip;

            client.Save();

            return client;
        }

        public static Client FindByEmail(string email)
        {
            var q = new ClientQuery();
            q.Where(q.Email == email);

            var client = new Client();

            if(client.Load(q))
                return client;

            return null;
        }
    }
}
